/**
 * Created by Ren on 2015/6/6.
 */
function Boss(ctx, x, y, player, enemyBullet, img, bulletAudio, boss)
{
    this.ctx = ctx;
    this.img = new Image();
    this.img.src = img;
    this.explodedImg = new Image();
    this.explodedImg.src = "images/BeiJi_02.png";
    this.player = player;
    this.enemyBullet = enemyBullet;
    this.bulletAudio = bulletAudio;
    this.x = x;
    this.y = y;
    this.life = 300;
    this.isShow = false;
    this.exploded = false;
    this.bulSpeed = 4;
    this.fireTime = 0;
    this.explodedIndex = 0;
    this.width = 128;
    this.height = 128;
    this.boss= boss;
    this.direction = 1;
}
Boss.prototype.draw = function()
{
/*    console.log(this.life);*/
    if(++this.fireTime > gameStatus.game_bossFireSpeed)
    {
        this.fire();
        this.fireTime = 0;
    }
    if(!this.exploded)
    {
        if(this.isShow)
        {
            this.explosion();
        }
        if(this.life < 200)
        {
            this.life += 0.01;
        }
        if(this.y < 0)
        {
            this.y += 3;
        }
        else
        {
            this.y = 0;
        }
        if(this.direction == 1)
        {
            this.x += 4;
            if(this.x > 472)
            {
                this.direction = 2;
            }
        }
        else
        {
            this.x -= 4;
            if(this.x < 0)
            {
                this.direction = 1;
            }
        }
        drawImage2(this.ctx, this.img, 0, 0, this.width, this.height, this.x, this.y, Math.PI, 128, 128);
    }
    else
    {
        this.explosion();
        this.boss.remove(this);
    }
}
Boss.prototype.getCenter=function() {
    return new Point(this.x + this.width/2, this.y + this.height/2);
}
Boss.prototype.fire = function()
{
    var bullet1 = new Bullet(this.ctx, this.x + 64, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, Math.PI, 16, 28);
    var bullet2 = new Bullet(this.ctx, this.x + 44, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 210*Math.PI/180, 16, 28);
    var bullet3 = new Bullet(this.ctx, this.x + 24, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 240*Math.PI/180, 16, 28);
    var bullet4 = new Bullet(this.ctx, this.x + 84, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 150*Math.PI/180, 16, 28);
    var bullet5 = new Bullet(this.ctx, this.x + 104, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 120*Math.PI/180, 16, 28);
    var bullet6 = new Bullet(this.ctx, this.x + 34, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 225*Math.PI/180, 16, 28);
    var bullet7 = new Bullet(this.ctx, this.x + 54, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 195*Math.PI/180, 16, 28);
    var bullet8 = new Bullet(this.ctx, this.x + 74, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 165*Math.PI/180, 16, 28);
    var bullet9 = new Bullet(this.ctx, this.x + 94, this.y+128, this.enemyBullet, this.bulSpeed, 8, "images/projectile.png", this.bulletAudio, 135*Math.PI/180, 16, 28);
    this.enemyBullet.push(bullet1);
    this.enemyBullet.push(bullet2);
    this.enemyBullet.push(bullet3);
    this.enemyBullet.push(bullet4);
    this.enemyBullet.push(bullet5);
    this.enemyBullet.push(bullet6);
    this.enemyBullet.push(bullet7);
    this.enemyBullet.push(bullet8);
    this.enemyBullet.push(bullet9);
}
Boss.prototype.explosion=function() {
    if(this.exploded)
    {
        if(this.explodedIndex < 9)
        {
            this.ctx.drawImage(this.explodedImg,this.explodedIndex*128, 0, 128, 129, this.x,this.y, 128, 129);
            this.explodedIndex ++;
        }
    }
    else
    {
        if(this.explodedIndex < 4)
        {
            this.ctx.drawImage(this.explodedImg,this.explodedIndex*128, 0, 128, 129, this.x,this.y, 128, 129);
            this.explodedIndex ++;
        }
        this.isShow = false;
        this.explodedIndex = 0;
    }
}